#ifndef bgsource_H
#define bgsource_H

#include "../page.h"

/**
 * Provides information and a pixmap for a Page's background.
 */
class BGSource : public QObject
{
    Q_OBJECT

public:
    /**
     * Creates a new BGsource with the given Page as a parent.
     */
    BGSource(Page *parent);

    /**
    * When true, the background has a preferred size.
    * This is used by PDF pages or other imported backgrounds that
    * cannot work with any given size.
    * 
    * The default implementation returns false;
    */
    virtual bool hasPreferredSize() const { return false; }

    /**
    * Returns the preferred size of this background.
    * Only needs to be implemented when hasPreferredSize is true
    * for the implementation.
    * 
    * Default returns QSizeF(0,0) as it does not have a preferred size.
    */
    virtual QSizeF getPreferredSize() const { return QSizeF(0,0); }

    /**
    * Orders the background to render itself on a QPixmap with the given size.
    * 
    * The result will be delivered by emitting the signal bgRendered. This
    * is done with a signal, to allow the pixmap creation to be done in an
    * extra thread.
    */
    virtual void renderBackgroundPixmap(QSizeF size) = 0;

    /**
    * True when the bg source is still rendering. When false
    * it is ready to for the next call to renderBackgroundPixmap.
    */
    virtual bool rendering() = 0;

    /**
     * Return a copy of this background source.
     */
    virtual BGSource* deepCopy();

signals:
    /**
     * Emitted when this background has rendered itself into a
     * qpixmap to display it on a page.
     * 
     * Emitted by renderBackgroundPixmap.
     */
    void bgRendered(QPixmap *pixmap);
};

#endif